#include <iostream>
using std::cout;
using std::endl;

class Circle{
public:
    // 构造方法
    Circle();
    Circle(double r);

    // 成员方法
    double getArea();
    double getPerimeter();
    void show();
private:
    double _r;
};

class Cylinder: public Circle{
public:
    // 构造方法
    Cylinder();
    Cylinder(double r, double h);

    // 成员方法
    double getVolume();
    void showVolume();

private:
//   Circle _circle;    // 此处无需重写
    double _height;
};

Circle::Circle()
    :_r(0)
{}

Circle::Circle(double r)
    :_r(r)
{}

double Circle::getArea(){
    return _r*_r*3.14;
}

double Circle::getPerimeter(){
    return _r*3.14*2;
}

void Circle::show(){
    cout << "r:" << _r << '\n';
    cout << "A:" << getArea() << '\n';
    cout << "P:" << getPerimeter() << endl;
}

Cylinder::Cylinder()
    :Circle(0)
    ,_height(0)
{}

Cylinder::Cylinder(double r, double h)
    :Circle(r)
    ,_height(h)
{}

double Cylinder::getVolume(){
    return getArea()*_height;
}

void Cylinder::showVolume(){
//    show();
    cout << "V:" << getVolume() << endl;
}

void test(){
    Circle c1;
    c1.show();
    Circle c2(5);
    c2.show();
}

void test2(){
    Cylinder cy1;
    cy1.show();
    cy1.showVolume();
    Cylinder cy2(3, 4);
    cy2.show();
    cy2.showVolume();
}

int main()
{
    test2();
    return 0;
}

